/**
 * 创建表格
 * @param titles    标题数组
 * @param data      数据数组
 * 封装
 */
function createTable(titles, data) {
    if (!Array.isArray(titles)) {
        throw new Error("titles 必须是一个数组");
    }
    if (!Array.isArray(data)) {
        throw new Error("data 必须是一个数组");
    }
    // 创建table标签
    let table = document.createElement("table");
    table.border = "1"; // 设置边框属性

    let thead = document.createElement("thead");
    let tbody = document.createElement("tbody");
    // 将thead和tbody添加到table标签中
    table.appendChild(thead);
    table.appendChild(tbody);
    // 将table添加到body标签中
    document.body.appendChild(table);
    // 编写标题
    // tr
    let tr = document.createElement("tr");
    thead.appendChild(tr);
    titles.forEach(value => {
        let th = document.createElement("th");
        th.innerHTML = value;
        tr.appendChild(th);
    })

    // 内容
    data.forEach((value, index) => {
        tr = document.createElement("tr");
        tbody.appendChild(tr);
        let td = document.createElement("td");
        let cb_select = document.createElement("input");
        cb_select.type = "checkbox";
        cb_select.value = "1";
        cb_select.name = "cb_select";
        td.appendChild(cb_select);
        tr.appendChild(td);

        for (let key in value) {
            td = document.createElement("td");
            td.textContent = value[key];
            td.className = "td_center";
            if (key == "count") {
                td.innerHTML = `
                    <button type="button">-</button>
                    ${value[key]}
                    <button type="button">+</button>
                `;
            }
            tr.appendChild(td);
        }

        td = document.createElement("td");
        td.className = "td_center";
        td.innerHTML = `
        <button type="button">编辑</button>
        <button type="button">删除</button>
    `;
        tr.appendChild(td);
    })
}